import { find } from "lodash";
import styles from "./index.module.less";
import cs from 'classnames';
import { DragOutlined } from '@ant-design/icons';

export const getTableColumns = ({ taskStatusList, taskTypeList, taskRouteList, vehType }: any) => [
	{
		title: "拖拽",
		width: 60,
		fixed: "left",
		dataIndex: "drag-handle",
		render: () => <DragOutlined style={{ cursor: "move", color: "#999" }} />
	},
	{
		title: "任务编号",
		dataIndex: "id",
		width: 140,
		ellipsis: true
	},
	{
		title: "任务名称",
		dataIndex: "jobName",
		width: 140,
		ellipsis: true
	},
	{
		title: "任务类型",
		dataIndex: "jobType",
		width: 140,
		ellipsis: true,
		render: (_: any, record: any) => {
			const result = find(taskTypeList, (item: any) => item.value === record.jobType)
			return (
				<div>
					{ result?.label }
				</div>
			)
		}
	},
	{
		title: "路线类型",
		dataIndex: "rtType",
		width: 140,
		ellipsis: true,
		render: (_: any, record: any) => {
			const result = find(taskRouteList, (item: any) => item.value === record.rtType)
			return (
				<div>
					{ result?.label }
				</div>
			)
		}
	},
	{
		title: "车牌号",
		dataIndex: "plateNo",
		width: 100,
		ellipsis: true,
	},
	{
		title: "任务状态",
		dataIndex: "jobStatus",
		width: 100,
		ellipsis: true,
		render: (_: any, record: any) => {
			const result = find(taskStatusList, (item: any) => item.value === record.jobStatus)
			const classValue = () => {
				switch(record.jobStatus) {
					case 0:
						return styles.warning
					case 1:
						return styles.success
					case 2:case 4:case 5:
						return styles.gray
					case 3:
						return styles.error
				}
			}
			return (
				<div className={cs(styles.taskStatus, classValue())}>
					<i></i>
					<span>{result?.label}</span>
				</div>
			)
		}
	},
	{
		title: "任务车辆",
		dataIndex: "vehType",
		width: 100,
		ellipsis: true,
		render: (_: any, record: any) => {
			const result = find(vehType, (item: any) => item.value === record.vehType)
			return <div>{result?.label || "-"}</div>;
		}
	},
	{
		title: "创建日期",
		dataIndex: "createTime",
		width: 140,
		ellipsis: true
	},
];

export const USER_STATUS = [
	{ label: '在线', value: 1 },
	{ label: '离线', value: 2 }
]

export const getSearchColumns = ({taskStatusList, taskTypeList}: any) => [
	{
		type: "input",
		placeholder: "任务编号",
		name: "id"
	},
	{
		type: "input",
		placeholder: "任务名称",
		name: "jobName"
	},
	{
		type: "input",
		placeholder: "车牌号",
		name: "plateNo"
	},
	{
		type: "select",
		placeholder: "任务类型",
		name: "jobType",
		options: taskTypeList
	},
	{
		type: "select",
		placeholder: "任务状态",
		name: "jobStatus",
		options: taskStatusList
	},
]